<template>
    <div class="app-container">
        <el-card class="filter-container" shadow="never" style="margin-bottom: 20px;">
            <div>
                <i class="el-icon-search"></i>
                <span>筛选搜索</span>
                <el-button style="float: right" @click="searchBrandList()" type="primary" size="small">查询结果</el-button>
            </div>
            <div style="margin-top: 15px">
                <el-form :inline="true" :model="listQuery" size="small" label-width="140px">
                    <el-form-item label="输入搜索：">
                        <el-input style="width: 203px" v-model="listQuery.keyword" placeholder="品牌名称/关键字"></el-input>
                    </el-form-item>
                </el-form>
            </div>
        </el-card>
        
        <el-card class="operate-container" shadow="never" style="margin-bottom: 20px;">
            <i class="el-icon-tickets"></i>
            <span>数据列表</span>
            <el-button class="btn-add" @click="addBrand()" size="mini">添加</el-button>
        </el-card>

        <div class="table-container">
            <el-table ref="brandTable" :data="list" style="width: 100%" @selection-change="handleSelectionChange" border>
                <el-table-column type="selection" width="60" align="center"></el-table-column>
                <el-table-column label="编号" width="100" align="center">
                    <template slot-scope="scope">{{scope.row.id}}</template>
                </el-table-column>
                <el-table-column label="品牌名称" align="center">
                    <template slot-scope="scope">{{scope.row.name}}</template>
                </el-table-column>
                <el-table-column label="品牌首字母" width="100" align="center">
                    <template slot-scope="scope">{{scope.row.firstLetter}}</template>
                </el-table-column>
                <el-table-column label="排序" width="100" align="center">
                    <template slot-scope="scope">{{scope.row.sort}}</template>
                </el-table-column>
                <el-table-column label="品牌制造商" width="100" align="center">
                    <template slot-scope="scope">
                        <el-switch  @change="handleFactoryStatusChange(scope.$index, scope.row)" disabled :active-value="1" :inactive-value="0" v-model="scope.row.factoryStatus"></el-switch>
                    </template>
                </el-table-column>
                <el-table-column label="是否显示" width="100" align="center">
                    <template slot-scope="scope">
                        <el-switch @change="handleShowStatusChange(scope.$index, scope.row)" disabled :active-value="1" :inactive-value="0" v-model="scope.row.showStatus"></el-switch>
                    </template>
                </el-table-column>
                <el-table-column label="相关" width="220" align="center">
                    <template slot-scope="scope">
                        <span>商品：</span>
                        <el-button size="mini" type="text" @click="getProductList(scope.$index, scope.row)">100</el-button>
                        <span>评价：</span>
                        <el-button size="mini" type="text" @click="getProductCommentList(scope.$index, scope.row)">1000</el-button>
                    </template>
                </el-table-column>
                <el-table-column label="操作" width="200" align="center">
                    <template slot-scope="scope">
                        <el-button size="mini" @click="updateBrand(scope.$index, scope.row)">编辑</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>

        <div class="pagination-container" style="margin-top: 10px;">
            <el-pagination background  layout="total, sizes,prev, pager, next,jumper" @size-change="handleSizeChange"
            :page-size="listQuery.pageSize" :page-sizes="[5,10,15]" :current-page.sync="listQuery.pageNum" :total="total"></el-pagination>
        </div>
    </div>
</template>
<script>
import BrandDetail from './components/BrandDetail'
import {deletePmsBrand, queryPmsBrandList} from '@/api/pms/brand'
export default {
    name: 'indexBrand',
    components: { BrandDetail },
    data() {
        return {
            listQuery: {
                keyword: '',
                pageNum: 1,
                pageSize: 10,
            },
            list:[
  
            ],
            total: null,
            listLoading: true,
            multipleSelection: []
        }
    },
    created() {
      this.getList();
    },
    methods: {
        getList() {
            let params = this.listQuery;
            queryPmsBrandList(params).then(response => {
                let data = response.data.data;
                this.list = data.list;
                this.total = data.total;
                this.totalPage = data.totalPage;
                this.pageSize = data.pageSize;
            });
        },
        searchBrandList() {
            this.listQuery.pageNum = 1;
            this.getList();
        },
        // 表格选中的数据变更(用于多选操作)
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },
        // 是否为品牌制造商状态变更(暂时禁用)
        handleFactoryStatusChange(index, row) {

        },
        // 是否展示状态变更(暂时禁用)
        handleShowStatusChange(index, row) {

        },
        // 获取商品列表
        getProductList(index, row) {
            this.$message({
                message: '该功能暂未开放',
                type: 'success',
                duration: 1000
            });
        },
        // 获取商品评论列表
        getProductCommentList(index, row) {
            this.$message({
                message: '该功能暂未开放',
                type: 'success',
                duration: 1000
            });
        },
        // 添加和编辑按钮,跳转到各自的路由上面
        addBrand() {
            this.$router.push({path: '/branAdd'})
        },
        updateBrand(index, row) {
            this.$router.push({path: '/brandUpdate', query: {id: row.id}})
        },
        handleDelete(index, row) {
            this.$confirm('是否要删除该品牌', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                deletePmsBrand(row.id, {}).then(response => {
                    this.$message({
                        message: '删除成功',
                        type: 'success',
                        duration: 1000
                    });
                    this.getList();
                })
            })
        },
        // 处理每页个数变更
        handleSizeChange(val) {
            this.listQuery.pageNum = 1;
            this.listQuery.pageSize = val;
            this.getList();
        },
        // 处理页数变更
        handleCurrentChange(val) {
            this.listQuery.pageNum = val;
            this.getList();
        },
    }
}
</script>
<style>

</style>